<?php
/**
 * Created by PhpStorm
 * User: Jhinwy
 * Date: 5/9/24
 * Time: 3:24 PM
 */

namespace app\adminapi\lists\jump;

use app\adminapi\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\model\jump\Jump;
use app\common\model\quickapp\Quickapp;


/**
 * 跳转配置（企微、快应用）
 *
 * Class OrderLists
 * @package app\adminapi\lists
 */
class JumpLists extends BaseAdminDataLists implements ListsSearchInterface
{


    /**
     * 搜索条件
     *
     * @return array
     */
    public function setSearch(): array
    {
        return [
            '='      => ['platform'],
        ];
    }


    public function queryWhere(): array
    {
        return [];
    }


    public function count(): int
    {
        return Jump::where($this->searchWhere)->count();
    }


    /**
     * 获取列表
     *
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function lists(): array
    {
        $list = Jump::field('id, title, platform, admin_id, type, jump_url, status, create_time, update_time')
            ->append(['admin_name', 'platform_name'])
            ->where($this->searchWhere)
            ->order('create_time', 'desc')
            ->limit($this->limitOffset, $this->limitLength)
            ->select()
            ->toArray();
        foreach ($list as &$item){
            $item['enterprise_wechat'] = Quickapp::where('id',$item['platform'])->value('enterprise_wechat')??0;
        }
        return $list;
    }
}
